#!/bin/bash
Get_Kubedns_Status(){
   echo "############################ 收集KubeDNS信息 #############################"
   # 集群内网域名检测
   DNSServerIP=$(kubectl  get svc -n kube-system |grep kube-dns | awk '{print $3}')
   echo "DNSServerIP $DNSServerIP"
   kubernetesSvcIP=$(kubectl  get svc  |grep kubernetes | awk '{print $3}')

   if command -v nslookup >/dev/null 2>&1; then
        resultForNslookup=$(nslookup kubernetes.default.svc.cluster.local $DNSServerIP)
        echo -e "解析结果: \n$resultForNslookup"
        resolvedIP=$(echo "$resultForNslookup" |awk '/Address/'| awk 'NR==2 {print $2}')
   else
       echo "nslookup not found"
       return 1
   fi

   if [ "$kubernetesSvcIP" = "$resolvedIP" ]; then
       echo "info:内网解析正常"
   else
       echo "warn:内网解析失败"
       return 1
   fi
}

Get_Kubedns_Status